<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>websocket测试例子</title>
</head>
<body>
    <button id="btn-connect">点击关闭连接websocket</button>
    <script  type="module">
        import {connectWebsocket, closeWebsocket} from './js/websocket.js';
        connectWebsocket(
            // 测试地址
            'wss://echo.websocket.org',
            // 传递给后台的数据
            {},
            // 成功拿到后台返回的数据的回调函数
            (data) => {
                console.log('成功的回调函数, 接收到的data数据： ', data)
            },
            // websocket连接失败的回调函数
            () => {
                console.log('失败的回调函数')
            }
        );

        document.getElementById('btn-connect').onclick = ()=> {
            closeWebsocket();
        }
    </script>
</body>
</html>